package com.zyf.wjy.dao;

import com.fasterxml.jackson.core.type.TypeReference;
import com.zyf.wjy.entity.Material;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 农资DAO
 */
@Repository
public class MaterialDao extends BaseDao<Material> {
    
    @Override
    protected String getFileName() {
        return "materials.json";
    }
    
    @Override
    protected TypeReference<List<Material>> getTypeReference() {
        return new TypeReference<List<Material>>() {};
    }
    
    @Override
    protected Long getId(Material entity) {
        return entity.getId();
    }
    
    @Override
    protected void setId(Material entity, Long id) {
        entity.setId(id);
    }
    
    /**
     * 根据农资类型查询
     */
    public List<Material> findByType(String materialType) {
        return findAll().stream()
            .filter(material -> materialType.equals(material.getMaterialType()))
            .toList();
    }
}

